#include "String.h"

typedef struct __msgrtn
{
	int fi;			//I
	int fq;			//Q
	AStr furi;		//from F: 
	AStr fsid;		//from furi
	AStr text;		//Content
	int type;	//{BN M I IN O R etc.}
} rmsg_info;

class MsgRtn
{
public:
	enum MsgType{ UNKOWN_,BN_,I_,M_,IN_,O_,R_,S_};
private:
	rmsg_info minfo;
public:
	MsgRtn()
	{
		minfo.fi = 0;
		minfo.fq = 0;
		minfo.type = UNKOWN_;
	}
	MsgRtn(AStr rtnmsg)
	{
		Parse(rtnmsg);
	}
	
	void Parse(AStr rtnmsg)
	{
		minfo.fi = rtnmsg.get("I: ","\r\n").toi();
		minfo.fq = rtnmsg.get("Q: "," ").toi();
		minfo.furi = rtnmsg.get("F: ","\r\n");
		minfo.fsid = minfo.furi.get("sip:","@");
		minfo.text = rtnmsg.mid("\r\n\r\n");
		AStr type = rtnmsg.left(" ");
		minfo.type = UNKOWN_;
		if (type=="BN") minfo.type = BN_;
		if (type=="I" ) minfo.type = I_;
		if (type=="M" ) minfo.type = M_;
		if (type=="IN") minfo.type = IN_;
		if (type=="O" ) minfo.type = O_;
		if (type=="R" ) minfo.type = R_;
		if (type=="S" ) minfo.type = S_;
	}
	rmsg_info get(AStr rtnmsg)
	{
		if (rtnmsg.isne()) Parse(rtnmsg);
		return minfo;
	}
};
